﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace kinect_music_shooter.GameWorld
{
    class Tunnel : GameObject
    {
        public void Update()
        {
            //rotation.Y += 0.2f;
            //rotation.Z += 0.02f;
            position.Z -= 2.7f;
            if (position.Z < -250.0f)
            {
                position.Z = 250.0f;
            }
        }

        public override void Draw(GraphicsDevice graphicsDevice, Camera camera)
        {
            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.PreferPerPixelLighting = true;

                    effect.FogEnabled = true;
                    effect.FogStart = 0.0f;
                    effect.FogEnd = 700.0f;
                    effect.FogColor = new Vector3(0.0f, 0.0f, 0.0f);

                    effect.World =
                        Matrix.CreateFromYawPitchRoll(
                        rotation.Y,
                        rotation.X,
                        rotation.Z) *

                        Matrix.CreateScale(scale) *

                        Matrix.CreateTranslation(position);


                    effect.DirectionalLight0.DiffuseColor = new Vector3(0.1f, 0.1f, 0.1f); // a red light
                    effect.DirectionalLight0.Direction = new Vector3(5, -5, -10);  // coming along the x-axis
                    effect.DirectionalLight0.SpecularColor = new Vector3(1, 0, 0); // with red highlights
                    effect.AmbientLightColor = new Vector3(0.2f, 0.2f, 0.2f);
                    effect.EmissiveColor = new Vector3(0.2f, 0.2f, 0.2f);

                    effect.Projection = camera.Projection;
                    effect.View = camera.View;
                    //effect.TextureEnabled = true;
                    //effect.Texture = tunnelText;
                }
                mesh.Draw();
                position.Z += 500.0f;
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.PreferPerPixelLighting = true;

                    effect.FogEnabled = true;
                    effect.FogStart = 0.0f;
                    effect.FogEnd = 700.0f;
                    effect.FogColor = new Vector3(0.0f, 0.0f, 0.0f);

                    effect.World =
                        Matrix.CreateFromYawPitchRoll(
                        rotation.Y,
                        rotation.X,
                        rotation.Z) *

                        Matrix.CreateScale(scale) *

                        Matrix.CreateTranslation(position);


                    effect.DirectionalLight0.DiffuseColor = new Vector3(0.1f, 0.1f, 0.1f); // a red light
                    effect.DirectionalLight0.Direction = new Vector3(5, -5, -10);  // coming along the x-axis
                    effect.DirectionalLight0.SpecularColor = new Vector3(1, 0, 0); // with red highlights
                    effect.AmbientLightColor = new Vector3(0.2f, 0.2f, 0.2f);
                    effect.EmissiveColor = new Vector3(0.2f, 0.2f, 0.2f);

                    effect.Projection = camera.Projection;
                    effect.View = camera.View;
                    //effect.TextureEnabled = true;
                    //effect.Texture = tunnelText;
                }
                position.Z -= 500.0f;
                mesh.Draw();
            }
        }
    }
}